using System.Collections.ObjectModel;
using System.IO;
using Common;
using Common.NotifyEvent;

namespace SExperiment
{
	public class StandardCurveManage : NotifyPropertyChanged
	{
		private ObservableCollection<ProjectStdCurve> _Items = new ObservableCollection<ProjectStdCurve>();

		public ObservableCollection<ProjectStdCurve> Items
		{
			get
			{
				return _Items;
			}
		}

		public void LoadAllStandardCurve()
		{
			string[] files = Directory.GetFiles(Utility.GetStandardPath(), "*." + Experiment.FileStdExt, SearchOption.TopDirectoryOnly);
			foreach (string file in files)
			{
				ProjectStdCurve projectStdCurve = new ProjectStdCurve();
				if (projectStdCurve.Read(file))
				{
					Items.Add(projectStdCurve);
				}
			}
		}

		public void SaveToStream(StreamEx stream)
		{
			stream.Write(Items.Count);
			foreach (ProjectStdCurve item in Items)
			{
				item.SaveToStream(stream);
			}
			stream.Flush();
		}

		public bool ReadFromStream(StreamEx stream)
		{
			int num = stream.ReadInt();
			for (int i = 0; i < num; i++)
			{
				ProjectStdCurve projectStdCurve = new ProjectStdCurve();
				projectStdCurve.ReadFromStream(stream);
				if (!string.IsNullOrEmpty(projectStdCurve.ProjectName))
				{
					Items.Add(projectStdCurve);
				}
			}
			return true;
		}
	}
}
